import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AnswerForm, AnswerQuery, AnswerVO } from '@/api/exam/answer/types';

const apiPrefix = '/exam/answer/';
export const pageAnswer = (query?: AnswerQuery): AxiosPromise<AnswerVO[]> => {
  return request({
    url: apiPrefix + 'page',
    method: 'get',
    params: query
  });
};
/**
 * 查询答题列表
 * @param query
 * @returns {*}
 */

export const listAnswer = (query?: AnswerQuery): AxiosPromise<AnswerVO[]> => {
  return request({
    url: apiPrefix + 'list',
    method: 'get',
    params: query
  });
};

/**
 * 查询当前用户在指定项目下的答卷列表
 */
export const listAnswerByProject = (query?: any): AxiosPromise<AnswerVO[]> => {
  return request({
    url: apiPrefix + 'answerList',
    method: 'get',
    params: query
  });
};

/*查询排名列表*/
export const listAnswerRank = (query: any): AxiosPromise<AnswerVO[]> => {
  return request({
    url: apiPrefix + 'rank',
    method: 'get',
    params: query
  });
};
/*查询排名列表*/
export const listProjectsAnswer = (query: any): AxiosPromise<AnswerVO[]> => {
  return request({
    url: apiPrefix + 'projectsList',
    method: 'get',
    params: query
  });
};
/**
 * 查询答题详细
 * @param id
 */
export const getAnswer = (id: string | number): AxiosPromise<AnswerVO> => {
  return request({
    url: apiPrefix + id,
    method: 'get'
  });
};

/*根据项目ID和用户ID查询答卷信息*/
export const getAnswerInfo = (query?: any): AxiosPromise<AnswerVO> => {
  return request({
    url: apiPrefix + 'answerInfo',
    method: 'post',
    params: query
  });
};

/**
 * 新增答题
 * @param data
 */
export const addAnswer = (data: AnswerForm) => {
  return request({
    url: apiPrefix,
    method: 'post',
    data: data
  });
};

/**
 * 暂存答案
 */
export const tempSave = (data: AnswerVO) => {
  return request({
    url: apiPrefix+'tempSave',
    method: 'put',
    data: data
  });
};

/**
 * 保存答卷
 * @param data
 */
export const updateAnswer = (data: AnswerVO) => {
  return request({
    url: apiPrefix,
    method: 'put',
    data: data
  });
};

/**
 * 保存答卷
 * @param data
 */
export const updateAnswerScore = (data) => {
  return request({
    url: apiPrefix + 'editScore',
    method: 'put',
    data: data
  });
};

/**
 * 删除答题
 * @param id
 */
export const delAnswer = (id: string | number | Array<string | number>) => {
  return request({
    url: apiPrefix + id,
    method: 'delete'
  });
};
